using System;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.PersonalLoan
{
    public class PersonalLoanDB
    {
        public PersonalLoanDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public PersonalLoan GetPersonalLoan(Int64 PLID)
        {
            MyDatabase _Db = new MyDatabase();
            string _spName = "[sprocPLLoanSelectSingleItem]";
            PersonalLoan _result = null;
            DataTable _dt;
            SortedList _sPara = new SortedList();

            _sPara.Add("@PLID", PLID);

            _dt = _Db.GetDataTableBySP(_spName, _sPara);

            if (_dt != null && _dt.Rows.Count > 0)
            {
                _result = new PersonalLoan();
                _result = FillDataRecord(_dt);
            }

            return _result;
        }

        public Int64 Insert(PersonalLoan personalloan)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocPLLoanInsertUpdateSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@PLID", personalloan.PLID);
            _sPara.Add("@LoanType", personalloan.LoanType);
            _sPara.Add("@LoanAmount", personalloan.LoanAmount);
            _sPara.Add("@LoanPeriodYears", personalloan.LoanPeriodYears);
            _sPara.Add("@SurName", personalloan.SurName);
            _sPara.Add("@Email", personalloan.Email);
            _sPara.Add("@IdType", personalloan.IdType);
            _sPara.Add("@IdNo", personalloan.IdNo);
            _sPara.Add("@MobileNo", personalloan.MobileNo);
            _sPara.Add("@DOB", personalloan.DOB);
            _sPara.Add("@AnnualIncome", personalloan.AnnualIncome);
            _sPara.Add("@IncomeType", personalloan.IncomeType);
            _sPara.Add("@BankName", personalloan.BankName);
            _sPara.Add("RefCEUserId", personalloan.RefCEUserId);
            _sPara.Add("@ViewedDetailId", personalloan.ViewedDetailId);
            _sPara.Add("@Status", personalloan.Status);
            _sPara.Add("@Info1", personalloan.Info1);
            _sPara.Add("@Info2", personalloan.Info2);
            _sPara.Add("@Info3", personalloan.Info3);
            _sPara.Add("@Info4", personalloan.Info4);
            _sPara.Add("@Info5", personalloan.Info5);
            _sPara.Add("@Info6", personalloan.Info6);
            _sPara.Add("@Info7", personalloan.Info7);
            _sPara.Add("@Info8", personalloan.Info8);
            _sPara.Add("@Info9", personalloan.Info9);
            _sPara.Add("@Info10", personalloan.Info10);
            _sPara.Add("@Info11", personalloan.Info11);
            _sPara.Add("@Info12", personalloan.Info12);
            _sPara.Add("@Info13", personalloan.Info13);
            _sPara.Add("@Info14", personalloan.Info14);
            _sPara.Add("@Info15", personalloan.Info15);
            _sPara.Add("@Info16", personalloan.Info16);
            _sPara.Add("@Info17", personalloan.Info17);
            _sPara.Add("@Info18", personalloan.Info18);
            _sPara.Add("@Info19", personalloan.Info19);
            _sPara.Add("@Info20", personalloan.Info20);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        private PersonalLoan FillDataRecord(DataTable myDataTable)
        {
            PersonalLoan mypersonalLoan = new PersonalLoan();
            mypersonalLoan.PLID = Convert.ToInt64(myDataTable.Rows[0]["PLID"].ToString());
            mypersonalLoan.LoanType = Convert.ToInt16(myDataTable.Rows[0]["LoanType"].ToString());
            mypersonalLoan.LoanAmount = Convert.ToSingle(myDataTable.Rows[0]["LoanAmount"].ToString());
            mypersonalLoan.LoanPeriodYears = Convert.ToInt16(myDataTable.Rows[0]["LoanPeriodYears"].ToString());
            mypersonalLoan.SurName = myDataTable.Rows[0]["SurName"].ToString();
            mypersonalLoan.Email = myDataTable.Rows[0]["Email"].ToString();
            mypersonalLoan.MobileNo = myDataTable.Rows[0]["MobileNo"].ToString();
            mypersonalLoan.IdType = myDataTable.Rows[0]["IdType"].ToString();
            mypersonalLoan.IdNo = myDataTable.Rows[0]["IdNo"].ToString();
            mypersonalLoan.DOB = Convert.ToDateTime(myDataTable.Rows[0]["DOB"].ToString());
            mypersonalLoan.AnnualIncome = myDataTable.Rows[0]["AnnualIncome"].ToString();
            mypersonalLoan.IncomeType = Convert.ToInt16(myDataTable.Rows[0]["IncomeType"].ToString());
            mypersonalLoan.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());
            mypersonalLoan.CreatedDate = Convert.ToDateTime(myDataTable.Rows[0]["CreatedDate"].ToString());
            mypersonalLoan.ModifiedDate = Convert.ToDateTime(myDataTable.Rows[0]["ModifiedDate"].ToString());
            return mypersonalLoan;
        }

    }
}